package com.atguigu.config;

import com.atguigu.interceptor.MyInterceptor1;
import com.atguigu.interceptor.MyInterceptor2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author zhangchunsheng
 * @CreateTime: 2025/01/20
 */
@Configuration
public class SpringMVCConfig implements WebMvcConfigurer {

    @Autowired
    @Qualifier("myInterceptor1")
    private MyInterceptor1 myInterceptor1;

    @Autowired
    @Qualifier("myInterceptor2")
    private MyInterceptor2 myInterceptor2;

    //注册拦截器(URL)
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器(myInterceptor1)
        registry.addInterceptor(myInterceptor1).addPathPatterns("/interceptorController/testInterceptor");
        //注册拦截器(myInterceptor2)
        //registry.addInterceptor(myInterceptor2).addPathPatterns("/interceptorController/*");
        //registry.addInterceptor(myInterceptor2).addPathPatterns("/interceptorController/**"); //任意层任意数量任意字符
        registry.addInterceptor(myInterceptor2)
                .addPathPatterns("/interceptorController/*")                            //添加拦截URL
                .excludePathPatterns("/interceptorController/testInterceptor333");      //排除拦截URL
    }


}
